package pacman.entries.pacman;

import pacman.controllers.Controller;
import pacman.entries.pacman.meta_graph.MetaGraph;
import pacman.entries.pacman.meta_graph.MetaGraphEvaluator;
import pacman.entries.pacman.meta_graph.MetaGraphPath;
import pacman.game.Constants.MOVE;
import pacman.game.Game;

public class MetaGraphPacMan extends Controller<MOVE> {

	public MetaGraphPacMan(MetaGraphEvaluator evaluator) {
		m_Evaluator = evaluator;
	}
	
	int m_CurrentLevel = -1;
	MetaGraph m_MetaGraph = null;
	MetaGraphEvaluator m_Evaluator;
	
	@Override
	public MOVE getMove(Game game, long timeDue) {
		
		if (game.getCurrentLevel() != m_CurrentLevel) {
			m_MetaGraph = new MetaGraph(game, m_Evaluator);
			m_CurrentLevel = game.getCurrentLevel();
			return MOVE.NEUTRAL;
		}
		
		MetaGraphPath bestPath = m_MetaGraph.bestPath(game);
		if (bestPath == null) {
			System.out.println("bestPath was null...");
			return MOVE.NEUTRAL;
		}
			
		return bestPath.nextMove(game);
	}
}
